package com.pitaya.winwine.web;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.pitaya.winwine.domain.User;
import com.pitaya.winwine.repository.TagRepository;
import com.pitaya.winwine.service.UserService;

@Controller
@RequestMapping("/user")
public class UserAction {
	
	@Autowired
	private TagRepository tagRepository;

	@Autowired
	private UserService userService;
	
	@RequestMapping(value = "/tag/choose")
	public ModelAndView registerChooseTag() {
		List list = tagRepository.findByOrderByTypeAscIdAsc();
		return new ModelAndView("user/tag", "tagList", list);
	}
	
	@RequestMapping(value = "/tag/save", method = RequestMethod.POST)
	public String registerSaveTag(HttpSession session, String tags) {
		User user = (User) session.getAttribute("user");
		userService.addTags(user.getId(), tags);
		return "redirect:/";
	}
}
